﻿using System;
using Entity;
using BLL.Access;
using BLL;
using System.Data;

namespace Web.Pages.YongShui._13.LAIHANGL
{
    public partial class FenHuXXXX : BasePage
    {
        #region 属性

        #endregion
       
        #region 变量
        /// <summary>
        /// 来函信息BLL
        /// </summary>
        YS_LH_LAIHANXXProcess BllLaiHanXX = new YS_LH_LAIHANXXProcess();
        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL BllYongHuXX = new YS_YG_YONGHUXXBLL();
        /// <summary>
        /// 分户信息BLL
        /// </summary>
        YS_LH_FENHUXXBLL BllFenHuXX = new YS_LH_FENHUXXBLL();

        /// <summary>
        /// 来函用户信息
        /// </summary>
        YS_LH_YONGHUTZProcess BllLaiHanYHTZ = new YS_LH_YONGHUTZProcess();
        
        #endregion

        #region 事件

      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }
       

        #endregion

        #region 方法
        /// <summary>
        /// 初始化
        /// </summary>
        private void InitControl()
        {
            //UCLHShenQingXX.SetFenHuTxTModel(false);
            BindData();
            
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            string laihanbh = "";
            string yonghubh = "";
            int laihanid = 0;
            
            if (!int.TryParse(Request["id"], out laihanid))
            {
                return;
            }
            YS_LH_LAIHANXX laihanxx = BllLaiHanXX.SelectYS_LH_LAIHANXX(laihanid);

            if (laihanxx != null)
            {
                laihanbh = laihanxx.S_LAIHANBH;
                yonghubh = laihanxx.S_YONGHUBH;
            }
            string where = string.Format(" S_LAIHANBH='{0}' ", laihanbh);

            DataTable lhable = BllLaiHanXX.SelectYS_LH_LAIHANXXesDynamic(where, " ID desc", null);
            if (lhable == null)
            {
                return;
            }
            string id = lhable.Rows[0]["ID"].ToString();
            YS_LH_LAIHANXX lh = BllLaiHanXX.SelectYS_LH_LAIHANXX(Convert.ToInt32(id));
            if (lh == null)
            {
                return;
            }
            UCLHUserInfo.LoadInfo(laihanxx);
            //UCLHFenHuShuiBiaoList.LoadInfo(laihanxx);
            txtLY.Text = lh.S_SHENQINGLY;
            //UCLHShenQingXX.LoadInfo(laihanxx);
            UCLHShenPiXX_FH.LoadInfo(laihanxx);

            //DataTable userdt = BllYongHuXX.SelectYS_YG_YONGHUXXesDynamic(string.Format(" S_YONGHUH='{0}' and i_jlzt=0 and i_leixing=0", lh.S_YONGHUBH), "", null);
            ////20181128 分户审批完成后的用户号i_jlzt=-1，没有数据取站点会异常
            //if (userdt != null && userdt.Rows.Count > 0)
            //{
            //    where = " S_LAIHANBH='{0}' and  S_YUANYONGHuH='{1}' and  S_ZHANDIANBH='{2}' and S_GUANLIKBH='{3}'  and i_jlzt=0 ";
            //    where = string.Format(where, laihanxx.S_LAIHANBH, laihanxx.S_YONGHUBH, userdt.Rows[0]["S_ZHANDIANBH"], userdt.Rows[0]["S_GUANLIKBH"]);
            //}
            //else
            //{
            //    where = " S_LAIHANBH='{0}' and  S_YUANYONGHuH='{1}' and i_jlzt=0 ";
            //    where = string.Format(where, laihanxx.S_LAIHANBH, laihanxx.S_YONGHUBH);
            //}
            //DataTable dt = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where, " ID  ", null);

            //if (dt != null && dt.Rows.Count > 1)
            //{
            //    UCLHShenQingXX.SetJiHuaXXBind(lh.S_YONGHUBH,dt.Rows[0]["S_YONGHUH"].ToString(),1);
            //    UCLHShenQingXX.SetJiHuaXXBind(lh.S_YONGHUBH, dt.Rows[1]["S_YONGHUH"].ToString(), 2);
            //}
            //else if (dt != null && dt.Rows.Count > 1)
            //{
            //    UCLHShenQingXX.SetJiHuaXXBind(lh.S_YONGHUBH, dt.Rows[0]["S_YONGHUH"].ToString(), 1);
            //    UCLHShenQingXX.SetJiHuaXXBind(lh.S_YONGHUBH, dt.Rows[1]["S_YONGHUH"].ToString(), 2);
            //    UCLHShenQingXX.SetJiHuaXXBind(lh.S_YONGHUBH, dt.Rows[1]["S_YONGHUH"].ToString(), 3);
            //}
            //UCLHShenQingXX.SetEnabledTXT(true);

            where = " S_LAIHANBH='{0}' and S_YONGHUHFATHER='{1}' and i_jlzt=0 ";
            where = string.Format(where,lh.S_LAIHANBH,lh.S_YONGHUBH);
            DataTable FenHu = BllFenHuXX.SelectYS_LH_FENHUXXesDynamic(where,"",null);
            if (FenHu != null && FenHu.Rows.Count > 0)
            {
                eLaiHanLCBH lcbh = (eLaiHanLCBH)Convert.ToInt32(FenHu.Rows[0]["S_SHENPI"].ToString() == "" ? "0" : FenHu.Rows[0]["S_SHENPI"]);
                txtYeWuY.Text = FenHu.Rows[0]["S_YeWuY"].ToString();
                labZhuRen.Text = FenHu.Rows[0]["S_ZhuRen"].ToString();
                labJieShui.Text=FenHu.Rows[0]["S_JieShui"].ToString();

                labJiCai.Text = FenHu.Rows[0]["S_JiCai"].ToString();
                if (lcbh >= eLaiHanLCBH.业务员)
                {
                    if (lcbh == eLaiHanLCBH.节水科)
                    {
                        cZhuRen1.Checked = true;
                        cJieShui1.Checked = true;
                    }
                    if (lcbh == eLaiHanLCBH.主任)
                    {
                        cZhuRen1.Checked = true;
                    }
                    if (lcbh == eLaiHanLCBH.计财科)
                    {
                        cZhuRen1.Checked = true;
                        cJieShui1.Checked = true;
                        CJiCai1.Checked = true;
                    }
                }
            }
        }
        #endregion
    }
}